<?php

Class DoAgain extends CI_Model {
    
    function get_last_of($QuizId, $UserCode)
    {
        $this->db->select('*');
        $this->db->from('do_again');

        $this->db->where('QuizId' , $QuizId);
        $this->db->where('UserCode', $UserCode);
        
        $this->db->order_by('id', 'desc');
        $this->db->limit('1');
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->row_array();
        } else {
            return false;
        }
    }
            
    function insert($newRecord) {
        if ($this->db->insert('do_again', $newRecord)) {
            return "Đã thêm!";
        } else {
            return "Unable to add";
        }
    }
    
    function update($newRecord) {
        $this->db->where('id', $newRecord['id']);
        $this->db->update('do_again', $newRecord);
        return "Đã cập nhật!";
    }

    function delete($id) {
        $this->db->delete('do_again', array('id' => $id));
        return "Đã xóa!";
    }

    // get particular user detail		
    function get($id) {
        $query = $this->db->get_where('do_again', array('id' => $id));
        return $query->row_array();
    }

    function get_by_code_and_eid($user_code, $eid) {
        $query = $this->db->get_where('do_again', array('user_code' => $user_code, 'eid' => $eid));
        if ($query->num_rows() != 1) {
            return false;
        }
        return $query->row_array();
    }


    

}

?>
